<template>
   <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>宠物管理</el-breadcrumb-item>
      <el-breadcrumb-item>宠物列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear='clearQuery' >
            <el-button slot="append" icon="el-icon-search" @click="queryGoods" ></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
        <el-button type="primary" @click='addGood'>添加宠物</el-button>
        </el-col>
      </el-row>
    <el-table
    :data="petsList"
    stripe
    style="width: 100%">
     <el-table-column type="index" ></el-table-column>
        <el-table-column label="宠物名称" width="125px">
          <template slot-scope="scope">
            <span>{{"哈基咪"+scope.row.goods_id}}</span>
          </template>
        </el-table-column>
        <el-table-column label="宠物性别" width="125px">
          <template slot-scope="scope">
            <span>{{scope.row.goods_id%3==0?"公":"母"}}</span>
          </template>
        </el-table-column>
          <el-table-column label="宠物年龄" width="125px">
          <template slot-scope="scope">
            <span>{{scope.row.goods_id%14+1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="宠物品种"  width="125px">
           <template slot-scope="scope">
            <span>{{types[scope.row.goods_id%9]}}</span>
          </template>
        </el-table-column>
        <el-table-column label="宠物图片" width="225px">
           <template slot-scope="scope">
            <div style="width:120px;height:80px">
               <img width="120px" height="80px"  :src="imgs[scope.row.goods_id%8]" alt=""/>
             </div>
          </template> 
        </el-table-column>
        <el-table-column label="宠物价格(元)"  width="160px">
           <template slot-scope="scope">
            <span>{{scope.row.goods_id+500}}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="add_time" width="225px">
          <template slot-scope="scope">
            {{scope.row.add_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="160px">
          <template >
            <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
          </template>
        </el-table-column>
    </el-table>
     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagenum"
      :page-sizes="[7, 14, 21, 28]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total" background>
    </el-pagination>
      </el-card>
      </div>
</template>

<script>
import request from '../../api/index'
export default {
    name:'List1',
    data(){
        return {
        queryInfo:{
            query:'',
            pagenum:1,
            pagesize:7
        },
        petsList:[],
        total:'',
        types:["柯基","边牧","缅因","加菲","布偶","英国短毛猫","美国爱脚猫","无毛猫","阿拉斯加"],
        imgs:["/imgs/1.jpeg","/imgs/2.jpeg","/imgs/3.jpeg","/imgs/4.jpeg","/imgs/5.jpeg",
        "/imgs/6.jpeg","/imgs/7.jpeg","/imgs/8.jpeg",]
        }
        
    },
    created(){
        this.getGoodsList()
    },
    methods:{
      async  getGoodsList(){

            const {data:res}=await request({url:'/goods',method:'get',
                                            params:this.queryInfo});
            if(res.meta.status!==200){
               return this.$message.error("获取宠物信息失败！")
            }
            this.petsList=res.data.goods;
            this.total=res.data.total;
            this.$message.success("获取宠物信息成功！")
        },
        handleSizeChange(val) {
       this.queryInfo.pagesize=val
       this.getGoodsList()
      },
      handleCurrentChange(val) {
          this.queryInfo.pagenum=val;
          this.getGoodsList()
      },
      queryGoods(){
          this.getGoodsList()
      },
      clearQuery(){
          this.queryInfo.query=""
          this.getGoodsList()
      },
      addGood(){
          this.$router.push('/pets/add')
      }
    }

}
</script>

<style lang='less' scoped>

</style>